﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using NewDDSys.DATAOUT;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_JBCX : System.Web.UI.Page
{
    private string ku = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["用户信息.岗位"].ToString() == "作业长")
            ku = Session["用户信息.部门"].ToString();
        else
            ku = Request.QueryString["Ku"];
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ShowList(ku);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ExcelEdit report = new ExcelEdit();
        report.CreateExcel();
        report.CreateWorkSheet("交班记录");
        report.CellsUnite(1, 1, 1, 10);
        report.WriteData("交班记录", 1, 1);
        report.CellsAlignment(1, 1, 1, 10, ExcelEdit.ExcelHAlign.居中, ExcelEdit.ExcelVAlign.居中);
        report.WriteData("编号", 2, 1);
        report.WriteData("库区", 2, 2);
        report.WriteData("记录时间", 2, 3);
        report.WriteData("班别", 2, 4);
        report.WriteData("班组", 2, 5);
        report.WriteData("交班人", 2, 6);
        report.WriteData("设备状况", 2, 7);
        report.WriteData("延续业务", 2, 8);
        report.WriteData("备注", 2, 9);
        report.WriteData("修改时间", 2, 10);
        string kday = txtSday.Text.ToString();
        string eday = txtEday.Text.ToString();
        DataSet ds = BLLFactory.CreateJbBLL().JBCX(kday, eday, ku);
        report.WriteData(ds.Tables[0], 3, 1);
        string title = Session["用户信息.姓名"].ToString() + DateTime.Now.ToString("yyyyMMdd").Trim() + "交班记录";
        string savepath = "zbqk\\" + title + ".xls";
        string RepPath = Server.MapPath(savepath);

        report.SaveAs(RepPath); //文档路径
        report.Close();
        string filename = title + ".xls";

        string spath = "zbqk\\" + filename;
        string RPath = Server.MapPath(spath);
        FileInfo f = new FileInfo(RPath);
        if (f.Exists)
        {

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
            Response.ContentType = "application/msexcel";
            Response.WriteFile(RPath);
            Response.Flush();
            Response.Close();
            f.Delete();
        }


    }
    public string GetCut(string str, int len)
    {
        //如果字符串的长度大于传入的规定长度，多余的部分则用...代替，否则，直接返回该字符串
        if (str.Length > len)
        {
            return str.Substring(0, len) + "...";
        }
        else
        {
            return str;
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        ShowList(ku);
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string num;

            num = (string)((DataRowView)e.Row.DataItem).Row.ItemArray[0];


            //when mouse over
            e.Row.Attributes.Add("onmouseover", "this.className='GridView_onmouseover';");
            //when mouse out
            e.Row.Attributes.Add("onmouseout", "this.className='GridView_onmouseout';");
            //将光标设为手形
            e.Row.Attributes.Add("style", "cursor: hand;");
            //行链接
            e.Row.Attributes.Add("onclick", "window.location='JBJLCX.aspx?Num=" + num + "'");


        }
    }
    private void ShowList(string ku)
    {
        string kday = txtSday.Text.ToString();
        string eday = txtEday.Text.ToString();
        DataSet ds = BLLFactory.CreateJbBLL().JBCX(kday, eday, ku);
        if (ds != null)
        {
            GridView1.DataSource = ds.Tables[0];
        }
        else
        {
            GridView1.DataSource = null;
        }
        GridView1.DataBind();
    }
}
